/*
 * Copyright (C) 2011  Xu Haojie
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package net.poemcode.gzlib.search;

import java.util.ArrayList;
import java.util.List;

import net.poemcode.gzlib.common.CommonRequest;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class SearchRequest extends CommonRequest {

	private String booktype = "all";

	private String cmdACT = "list";

	private String col1 = "title";

	private String columnID = "1";

	private String endPubdate = "";

	private String isFastsearch = "true";

	private String libNUM = "11";

	private String marcformat = "all";

	private String matching = "radionbutton";

	private String mod = "oneXSL";

	private String orderSign = "true";

	private String pageNo = "1";

	private String raws = "20";

	private String searchSign = "";

	private String sortSign = "score_sort";

	private String startPubdate = "";

	private String val1 = "";

	private String xsl = "BOOK_list.xsl";
	
	public SearchRequest() {
	}
	
	public String getBooktype() {
		return booktype;
	}

	public void setBooktype(String booktype) {
		this.booktype = booktype;
	}

	public String getCol1() {
		return col1;
	}

	public void setCol1(String col1) {
		this.col1 = col1;
	}

	public String getEndPubdate() {
		return endPubdate;
	}

	public void setEndPubdate(String endPubdate) {
		this.endPubdate = endPubdate;
	}

	public String getFilter() {
		String filter = "";
		if (booktype.equals("all")) {
			StringBuilder builder = new StringBuilder();
			builder.append("(");
			builder.append(col1);
			builder.append(":");
			builder.append(val1);
			builder.append(")");
			filter =  builder.toString();
		} else if (booktype.equals("1")) {
			StringBuilder builder = new StringBuilder();
			builder.append("(");
			builder.append(col1);
			builder.append(":");
			builder.append(val1);
			builder.append(") AND (booktype:1*)");
			filter = builder.toString();
		} else if (booktype.equals("2")) {
			StringBuilder builder = new StringBuilder();
			builder.append("(");
			builder.append(col1);
			builder.append(":");
			builder.append(val1);
			builder.append(") AND (booktype:2*)");
			filter = builder.toString();
		}
		
		return filter;
	}

	public String getIsFastsearch() {
		return isFastsearch;
	}

	public void setIsFastsearch(String isFastsearch) {
		this.isFastsearch = isFastsearch;
	}

	public void setLibNUM(String libNUM) {
		this.libNUM = libNUM;
	}

	public String getMarcformat() {
		return marcformat;
	}

	public void setMarcformat(String marcformat) {
		this.marcformat = marcformat;
	}

	public String getMatching() {
		return matching;
	}

	public void setMatching(String matching) {
		this.matching = matching;
	}

	public String getMod() {
		return mod;
	}

	public void setMod(String mod) {
		this.mod = mod;
	}

	public String getOrderSign() {
		return orderSign;
	}

	public void setOrderSign(String orderSign) {
		this.orderSign = orderSign;
	}

	public String getPageNo() {
		return pageNo;
	}

	public void setPageNo(String pageNo) {
		this.pageNo = pageNo;
	}

	public String getRaws() {
		return raws;
	}

	public void setRaws(String raws) {
		this.raws = raws;
	}

	public String getSearchSign() {
		return searchSign;
	}

	public void setSearchSign(String searchSign) {
		this.searchSign = searchSign;
	}

	public String getSortSign() {
		return sortSign;
	}

	public void setSortSign(String sortSign) {
		this.sortSign = sortSign;
	}

	public String getStartPubdate() {
		return startPubdate;
	}

	public void setStartPubdate(String startPubdate) {
		this.startPubdate = startPubdate;
	}

	public void setVal1(String val1) {
		this.val1 = val1;
	}
	
	public String getVal1() {
		return this.val1;
	}
	
	@Override
	public List<NameValuePair> getHttpParamemters() {
		List<NameValuePair> formparams = new ArrayList<NameValuePair>();
		formparams.add(new BasicNameValuePair("booktype", booktype));
		formparams.add(new BasicNameValuePair("cmdACT", cmdACT));
		formparams.add(new BasicNameValuePair("col1", col1));
		formparams.add(new BasicNameValuePair("columnID", columnID));
		formparams.add(new BasicNameValuePair("endPubdate", endPubdate));
		formparams.add(new BasicNameValuePair("filter", getFilter()));
		formparams.add(new BasicNameValuePair("ISFASTSEARCH", isFastsearch));
		formparams.add(new BasicNameValuePair("libNUM", libNUM));
		formparams.add(new BasicNameValuePair("marcformat", marcformat));
		formparams.add(new BasicNameValuePair("matching", matching));
		formparams.add(new BasicNameValuePair("mod", mod));
		formparams.add(new BasicNameValuePair("orderSign", orderSign));
		formparams.add(new BasicNameValuePair("pageNo", pageNo));
		formparams.add(new BasicNameValuePair("raws", raws));
		formparams.add(new BasicNameValuePair("searchSign", searchSign));
		formparams.add(new BasicNameValuePair("sortSign", sortSign));
		formparams.add(new BasicNameValuePair("startPubdate", startPubdate));
		formparams.add(new BasicNameValuePair("val1", val1));
		formparams.add(new BasicNameValuePair("xsl", xsl));
		return formparams;
	}
	
}
